<template>
  <div class="add-container">
    <div class="add-top">
      <el-page-header @back="goBack" :content="gobacktitle"></el-page-header>
    </div>
    <div class="add-main">
      <div class="add-main-top">
        <el-descriptions
          title="报损单"
          direction="vertical"
          :column="3"
          border
          id="descriptions"
        >
          <el-descriptions-item label="报损单号">
            {{ ruleForm.baosundh }}
          </el-descriptions-item>
          <el-descriptions-item label="名称">
            {{ ruleForm.mingcheng }}
          </el-descriptions-item>
          <el-descriptions-item label="状态">
            {{ $util.getbsdzt(ruleForm.zhuangtai) }}
          </el-descriptions-item>
          <el-descriptions-item label="备注">
            {{ ruleForm.tips }}
          </el-descriptions-item>
          <el-descriptions-item label="创建人">
            {{ ruleForm.createName }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间">
            {{ ruleForm.createName }}
          </el-descriptions-item>
        </el-descriptions>
      </div>

      <div class="add-main-list2">
        <div class="add-main-tital">
          <p>
            报损任务单
            <el-button
              type="primary"
              icon="el-icon-printer"
              v-print="printObj"
              @click="print"
            >
              打印
            </el-button>
          </p>
        </div>
        <div class="table-list">
          <ux-grid
            border
            show-overflow
            ref="plxTable"
            keep-source
            height="tabheight"
            :highlightCurrentRow="false"
            widthResize
          >
            <ux-table-column
              type="index"
              title="序号"
              width="50"
            ></ux-table-column>

            <ux-table-column field="renwudh" title="任务单号"></ux-table-column>
            <ux-table-column field="guajia" title="挂架"></ux-table-column>
            <ux-table-column field="zhuangtai" title="状态">
              <template v-slot="scope">
                {{ $util.getBfrwdzt(scope.row.zhuangtai) }}
              </template>
            </ux-table-column>
            <ux-table-column
              field="createName"
              title="创建人"
            ></ux-table-column>
            <ux-table-column
              field="createTime"
              title="创建日期"
            ></ux-table-column>
          </ux-grid>
        </div>
      </div>
    </div>
    <div style="height: 0">
      <div id="print-content">
        <div class="print-top">
          <h2>报损单明细</h2>
          <!-- <p class="print-time">{{ printTime }}</p> -->
        </div>
        <table
          border="1"
          width="100%"
          align="center"
          cellpadding="0"
          cellspacing="0"
        >
          <thead>
            <tr align="center" valign="center" height="36">
              <th :colspan="2">报损单号</th>
              <th>名称</th>
              <th>创建人</th>
              <th :colspan="2">创建时间</th>
            </tr>
          </thead>
          <tbody>
            <tr align="center" valign="center" height="36">
              <td :colspan="2">{{ ruleForm.baosundh }}</td>
              <td>{{ ruleForm.mingcheng }}</td>
              <td>{{ ruleForm.createName }}</td>
              <td :colspan="2">{{ ruleForm.createTime }}</td>
            </tr>
          </tbody>
          <tbody>
            <tr align="center" valign="center" height="36">
              <th :colspan="1">备注</th>
              <td :colspan="5">{{ ruleForm.tips }}</td>
            </tr>
          </tbody>
          <thead>
            <tr align="center" valign="center" height="36">
              <td>序号</td>
              <td :colspan="4">挂架</td>
              <td>操作人签字</td>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="(item, index) in printlist"
              :key="index"
              align="center"
              valign="center"
              height="36"
            >
              <td>{{ index + 1 }}</td>
              <td :colspan="4">{{ item.guajia }}</td>
              <td></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
  import { getBFDbyid, getBFRWlistAll } from '@/api/kunei'
  export default {
    name: 'Page1Deatail',
    props: {
      gobacktitle: {
        type: String,
        default: '新增',
        required: true,
      },
      datarow: {
        type: Object,
        default: function () {
          return {}
        },
      },
    },
    data() {
      return {
        show: true,
        ruleForm: {
          rkdh: '',
          wzmc: '',
          wzqf: '',
          rkzt: '',
          rklx: '',
          rukudmx: [],
        },
        rules: {
          rkdh: [
            { required: true, message: '请输入入库单号', trigger: 'blur' },
          ],
        },
        tabheight: 500,
        centerDialogVisible: false,
        printlist: null,
        printObj: {
          id: 'print-content',
          popTitle: '打印',
          extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
          beforeOpenCallback(vue) {
            vue.printLoading = true
          },
          openCallback(vue) {
            vue.printLoading = false
          },
          closeCallback(vue) {
            console.log('关闭了打印工具')
          },
        },
        printTime: '',
        printTotal: 0,
      }
    },
    created() {},
    async mounted() {
      let { data } = await getBFDbyid({ id: this.datarow.id })
      this.ruleForm = Object.assign({}, data)
      this.getRwList()
    },
    methods: {
      async getRwList() {
        const res = await getBFRWlistAll({ baosund: this.ruleForm.baosundh })
        this.$refs.plxTable.reloadData(res.data)
        this.printlist = res.data
      },
      goBack() {
        this.$parent.detailshow = false
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!')
          } else {
            return false
          }
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields()
      },
      selectChange(e) {},
      uploadSuccess() {
        this.importShow = false
      },
      print() {
        let time = new Date()
        this.printTime = time.toLocaleString()
      },
    },
  }
</script>
<style lang="scss" scoped>
  .add-container {
    position: fixed;
    left: 0;
    top: 0.75rem;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background-color: #f6f8f9;
    padding: 0 0.2rem 1rem 0.2rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    .add-top {
      padding: 0.1rem 0;

      ::v-deep .el-page-header__title {
        font-size: 0.16rem !important;
      }
    }

    .add-main-tital {
      font-size: 18px;
      border-left: 10px solid rgb(121, 189, 255);
      padding-left: 10px;
      margin: 20px 0 20px;

      p {
        margin: 0;
      }
    }

    .add-main {
      flex: 1;
      font-weight: bold;
      display: flex;
      flex-direction: column;
      overflow: auto;

      .add-main-top {
        padding: 0 20px;
        background: #fff;

        ::v-deep {
          .el-descriptions__header {
            border-left: 10px solid #79bdff;
            margin: 20px 0;
          }

          .el-descriptions__title {
            padding-left: 10px;
            font-size: 18px;
          }

          .el-descriptions-item__label {
            font-weight: bold;
            color: #333;
          }
        }
      }

      .add-main-list2 {
        flex: 1;
        background: #fff;
        padding: 0 20px;
        box-sizing: border-box;

        .list-button-group {
          display: flex;
          flex-direction: row;
          padding-bottom: 20px;

          .button-item {
            padding: 0px 10px;
          }

          .button-item:first-child,
          &:last-child {
            padding: 0px 10px 0 0;
          }
        }
      }

      .el-button {
        font-size: 0.14rem !important;
      }

      ::v-deep {
        .elx-table--header-wrapper {
          background-color: rgb(233, 243, 255);
        }

        .elx-table {
          font-size: 0.14rem !important;
        }

        .elx-body--column {
          height: 0.48rem !important;
          line-height: 0.24rem;
        }

        .elx-header--column {
          background-image: none !important;
          height: 0.48rem !important;
        }
      }

      .submit-button {
        margin-top: 20px;
        display: flex;
        justify-content: center;
      }
    }
  }
  #print-content {
    padding: 20px;

    .print-top {
      text-align: center;

      h2 {
        text-decoration: underline;
        margin: 0 !important;
        font-size: 20px;
      }
    }

    .print-time {
      float: right;
      color: #000;
      font-size: 16px;
    }

    table {
      font-size: 14px;
      background-color: #f0f2f5;
      border-collapse: collapse;
      color: #454545;
      table-layout: auto;
      width: 100%;
      text-align: center;
      border-bottom-width: 1px;
      border-bottom-style: solid;
      border-bottom-color: #dadcde;

      thead {
        border-top-width: 1px;
        border-top-style: solid;
        border-top-color: #dadcde;
        line-height: 40px;
        font-weight: bold;
        color: #454c70;
      }

      tr {
        border-top-width: 1px;
        border-top-style: solid;
        border-top-color: #dadcde;
        line-height: 23px;
      }

      td {
        padding: 5px;
        font-size: 14px;
        width: 100px;
        word-break: break-all; // 元素换行
      }

      // // 斑马纹效果stripe
      // tr:nth-child(even) {
      //   background: #F5F7F9;
      // }

      // tr:nth-child(odd) {
      //   background: #FFF;
      // }
    }
  }
</style>
